package com.zero.qth.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zero.common.core.domain.page.PageDomain;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zero.common.annotation.log.Log;
import com.zero.common.core.basecontroller.BaseController;
import com.zero.common.core.domain.result.AjaxResult;
import com.zero.common.core.enums.BusinessType;
import com.zero.qth.domain.DriverBalanceDetail;
import com.zero.qth.service.IDriverBalanceDetailService;
import com.zero.common.core.utils.poi.ExcelUtil;
import com.zero.common.core.domain.page.TableDataInfo;

/**
 * 司机余额明细Controller
 * 
 * @author cai-xu-kun
 * @date 2025-09-17
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "司机余额明细")
@RequestMapping("/qth/driverBalanceDetail")
public class DriverBalanceDetailController extends BaseController {

    private final IDriverBalanceDetailService driverBalanceDetailService;

    /**
     * 查询司机余额明细分页
     */
    @ApiOperation("查询司机余额明细分页")
    @PreAuthorize("@ss.hasPermi('qth:driverBalanceDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(DriverBalanceDetail driverBalanceDetail) {
        PageDomain pageDomain = this.startPage();
        Page<DriverBalanceDetail> p = new Page<>(pageDomain.getPageNum(), pageDomain.getPageSize());
        Page<DriverBalanceDetail> page = driverBalanceDetailService.selectDriverBalanceDetailListPage(driverBalanceDetail, p);
        return this.getDataTable(page);
    }

    /**
     * 导出司机余额明细列表
     */
    @ApiOperation("导出司机余额明细列表")
    @PreAuthorize("@ss.hasPermi('qth:driverBalanceDetail:export')")
    @Log(title = "司机余额明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DriverBalanceDetail driverBalanceDetail) {
        List<DriverBalanceDetail> list = driverBalanceDetailService.selectDriverBalanceDetailList(driverBalanceDetail);
        ExcelUtil<DriverBalanceDetail> util = new ExcelUtil<DriverBalanceDetail>(DriverBalanceDetail.class);
        util.exportExcel(response, list, "司机余额明细数据");
    }

    /**
     * 获取司机余额明细详细信息
     */
    @ApiOperation("获取司机余额明细详细信息")
    @PreAuthorize("@ss.hasPermi('qth:driverBalanceDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(driverBalanceDetailService.selectDriverBalanceDetailById(id));
    }

    /**
     * 新增司机余额明细
     */
    @ApiOperation("新增司机余额明细")
    @PreAuthorize("@ss.hasPermi('qth:driverBalanceDetail:add')")
    @Log(title = "司机余额明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DriverBalanceDetail driverBalanceDetail) {
        return toAjax(driverBalanceDetailService.insertDriverBalanceDetail(driverBalanceDetail));
    }

    /**
     * 修改司机余额明细
     */
    @ApiOperation("修改司机余额明细")
    @PreAuthorize("@ss.hasPermi('qth:driverBalanceDetail:edit')")
    @Log(title = "司机余额明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DriverBalanceDetail driverBalanceDetail) {
        return toAjax(driverBalanceDetailService.updateDriverBalanceDetail(driverBalanceDetail));
    }

    /**
     * 删除司机余额明细
     */
    @ApiOperation("删除司机余额明细")
    @PreAuthorize("@ss.hasPermi('qth:driverBalanceDetail:remove')")
    @Log(title = "司机余额明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(driverBalanceDetailService.deleteDriverBalanceDetailByIds(ids));
    }
}
